package com.huajin.codetest.util;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Base64;

public class Base64Util {
	
	private Base64Util() {}
	
	public static String convertFileToBase64(String filepath) throws IOException {
		return Base64.getEncoder().encodeToString(Files.readAllBytes(Paths.get(filepath)));
	}
	
	public static void convertBase64ToFile(String fileBase64, String filepath) throws IOException {
		Files.write(Paths.get(filepath), Base64.getDecoder().decode(fileBase64), StandardOpenOption.CREATE);
	}
	
	public static void main(String[] args) throws IOException {
        convertBase64ToFile(convertFileToBase64("C:\\Users\\Chinawrr\\Desktop\\存证电子数据确认函_CWRR-BXKJ-0ROMH6K5OW0Q.pdf"), "D:\\data\\1.pdf");
    }

}
